package com.company;

import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        System.out.println("hello world");
//        MyBank bank = new MyBank(10000);
//        bank.init();
        List<Product> list=new ArrayList<Product>();
        for (int i=0; i<3; i++)
        {
          Product p=new Product();
            p.name="我是名字很长的名字该怎么显示..";
            p.bstring="多少斤/5kg";
            p.money="20我就是测试额是";
            list.add(p);
        }
        StringBuilder str=new StringBuilder();
        str.append("我是标题");
        str.append("\r\n");
        System.out.println(str);

        for (Product p: list) {
            List<PrintItem> sl=new ArrayList<PrintItem>();

            int j=0;
            while (j<p.name.length()) {
                int l = p.name.length() - 1 > j + 5 ? j + 5 : p.name.length() ;

                PrintItem pi = new PrintItem();
                pi.Item1 = p.name.substring(j, l);
                sl.add(pi);

                j += 5;
            }

            j=0;
            while (j<p.bstring.length()) {
                int l = p.bstring.length() - 1 > j + 5 ? j + 5 : p.bstring.length() ;
                PrintItem pi;
                Boolean isNew=false;
                if(sl.size()>= j/5)
                {
                    pi=sl.get(j/5);
                }
                else {
                    isNew=true;
                    pi = new PrintItem();
                }


                pi.Item2 = p.bstring.substring(j, l);

                if(isNew)
                    sl.add(pi);
                j += 5;
            }

            j=0;
            while (j<p.money.length()) {
                int l = p.money.length() - 1 > j + 5 ? j + 5 : p.money.length() ;
                PrintItem pi;
                Boolean isNew=false;
                if(sl.size()>= j/5)
                {
                    pi=sl.get(j/5);
                }
                else {
                    isNew=true;
                    pi = new PrintItem();
                }


                pi.Item3 = p.money.substring(j, l);

                if(isNew)
                    sl.add(pi);
                j += 5;
            }

            for (PrintItem pi: sl) {

                String ms="";
                ms+=pi.Item1==null||pi.Item1.isEmpty()?"     ":pi.Item1;

                ms+="  ";
                ms+=pi.Item2==null||pi.Item2.isEmpty()?"     ":pi.Item2;
                ms+="  ";
                ms+=pi.Item3==null||pi.Item3.isEmpty()?"     ":pi.Item3;

                System.out.println(ms);
            }
        }
    }

}

